import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Main {

    public static void main(String[] args) {


        ScheduledExecutorService service = Executors.newScheduledThreadPool(10);
        service.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
//                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd  HH:mm:ss");
                Calendar endCalender = Calendar.getInstance();
                endCalender.set(2018, 10, 26, 0, 0, 0);
                Date endTime = endCalender.getTime();
                long endTimeLong = endTime.getTime();

//                System.out.println("定死的结束时间：" + simpleDateFormat.format(endTime) + "\t" + endTimeLong);
                Calendar nowCalendar = Calendar.getInstance();
                Date nowTime = nowCalendar.getTime();
                long nowTimeLong = nowTime.getTime();
//                System.out.println("现在的时间：" + simpleDateFormat.format(nowTime) + "\t" + nowTimeLong);

                long ms = endTimeLong - nowTimeLong;
                int day = (int) (ms / (1000 * 60 * 60 * 24));
                int hour = (int) ((ms % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                int minute = (int) ((ms % (1000 * 60 * 60)) / (1000 * 60));
                int second = (int) ((ms % (1000 * 60)) / 1000);
                int millisecond = (int) (ms % 1000);
                System.out.println(day + "天\t" + hour + "小时\t" + minute + "分钟\t" + second + "秒\t" + millisecond+"毫秒");
            }
        }, 0, 1, TimeUnit.SECONDS);

    }
}
